package basicelement;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TendencyIndicator implements Serializable {
	
	public static String dateFormat = "dd/MM/yyyy HH:mm"; 
	public static String sell = "SELL";
	public static String buy = "BUY";
	
	private Date instantTime;
	private double lastPrice;
	private double lastLow;
	private double lastHigh;
	private double futureLow;
	private double futureHigh;
	
	
	
	
	public TendencyIndicator(String instantTime, double lastPrice, double lastLow, double lastHigh,
			double futureLow, double futureHigh) {
		super();
		try {
			this.instantTime = this.formatDate(instantTime);
		} catch (Exception e) {			 
			e.printStackTrace();  
		}  
		this.lastLow = lastLow;
		this.lastHigh = lastHigh;
		this.futureLow = futureLow;
		this.futureHigh = futureHigh;
	}
	
	public Date getInstantTime() {
		return instantTime;
	}
	public void setInstantTime(Date instantTime) {
		this.instantTime = instantTime;
	}
	public double getLastPrice() {
		return lastPrice;
	}
	public void setLastPrice(double lastPrice) {
		this.lastPrice = lastPrice;
	}

	public double getLastLow() {
		return lastLow;
	}
	public void setLastLow(double lastLow) {
		this.lastLow = lastLow;
	}
	public double getLastHigh() {
		return lastHigh;
	}
	public void setLastHigh(double lastHigh) {
		this.lastHigh = lastHigh;
	}
	public double getFutureLow() {
		return futureLow;
	}
	public void setFutureLow(double futureLow) {
		this.futureLow = futureLow;
	}
	public double getFutureHigh() {
		return futureHigh;
	}
	public void setFutureHigh(double futureHigh) {
		this.futureHigh = futureHigh;
	}
	
	public int getTendency(){
		int tendency = 0;
		if ((futureLow>lastLow)&&(futureHigh>lastHigh))
			tendency = 1;
		if ((futureLow<lastLow)&&(futureHigh<lastHigh))
			tendency = -1;
		return tendency;
	}
	
	
	 public static Date formatDate(String _data) throws Exception {   
		 if (_data == null || _data.equals(""))  
			 return null;  
		 Date date = null;  
		 try {  
			 DateFormat formatter = new SimpleDateFormat(dateFormat);  
			 date = (java.util.Date)formatter.parse(_data);  
		 } catch (ParseException e) {              
			 throw e;  
		 }  
		 	return date;  
	  }

	 public static String dateToString(Date _data) throws Exception {   
		 String date = null;  
		 if (_data != null){
			 try {  
				 DateFormat sdf = new SimpleDateFormat(dateFormat);  
				 date = sdf.format(_data);  
			 } catch (Exception e) {              
				 throw e;  
			 }  
		 }
	 	return date;  
	 }
	 
	@Override
	public String toString() {
		try {
			return "TendencyIndicator:" + dateToString(instantTime) + ";" + lastPrice + ";" +  
			lastLow  + ";" + lastHigh  + ";" + futureLow + ";" +
			futureHigh  + ";" + getTendency();
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}  

	 
}
